<?php
defined('BASEPATH') OR exit('No direct script access allowed');




class Customer extends MY_Controller {

	public function __construct() {
	    parent::__construct();
	    if($this->userinfo['group']!=1&&$this->userinfo['group']!=4 &&$this->userinfo['group']!=5&&$this->userinfo['group']!=6){
            $this->groupjunp($this->userinfo['group']);
        }
	}

	//主页
	public function index()	{

        $this->address='后台管理首页';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->model('Jd_task_jd_list_model');
        $month= $this->Jd_task_jd_list_model->getmonthdataall();
        $day= $this->Jd_task_jd_list_model->gettodayall();

        $days=explode("-",date('Y-m-d'));
        $days=intval($days[2]);

        $row['monthend']=0;
        $row['monthlost']=0;
        $row['daylost']=0;
        $row['dayend']=0;


        foreach ($month as $id=>$v){
            if($v['status']==1 ||$v['status']==0){
                $row['monthlost']+=$v['all'];
            }else{
                $row['monthend']+=$v['all'];
            }
        }

        foreach ($day as $id=>$v){
            if($v['status']==1 ||$v['status']==0){
                $row['daylost']+=$v['all'];
            }else{
                $row['dayend']+=$v['all'];
            }
        }
        $row['monthavg']=round($row['monthend']/$days,2);
        $this->load->view('Customer/index',$row);
	}


    /**
     * 订单检索
     */
    public function orderview()	{
        // $this->load->model('Jd_users_model');
        $this->address='单号检索';

        /*  $a=  $this->Jd_users_model->pageData(array('compare'=>array('id'=>1)),"*");*/
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/orderview');
    }


    /**
     * 获取订单列表
     */
    public function getorderviewlist($type=1){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if(empty($epage)){
            $epage=10;
        }
        $this->load->model('Jd_task_jd_list_model');
        $orderid = $this->input->post('orderid')? $this->input->post('orderid'):"";

        $shop_name = $this->input->post('shop_name')? $this->input->post('shop_name'):"";
        $username= $this->input->post('username')? $this->input->post('username'):"";


        $date1 = $this->input->post('date1')? $this->input->post('date1'):date('Y-m-d');
        $date2 = $this->input->post('date2')? $this->input->post('date2'):date('Y-m-d');

        $where="  where  p1.status=2  AND  p1.type=$type";
        if($date1){
            $date1=strtotime(date('Y-m-d 00:00:00',strtotime($date1)));
            $where.=" AND p1.finishtime>$date1 ";
        }
        if($date2){
            $date2=strtotime(date('Y-m-d 23:59:59',strtotime($date2)));
            $where.=" AND p1.finishtime<$date2 ";
        }
        if(!empty($orderid)){
            $orderid=trim($orderid);
            $where.=" AND p1.orderid= '$orderid'";
        }



        if(!empty($shop_name)){

            $shop_name=trim($shop_name);

            $where.=" AND p1.shop_name like '%$shop_name%'";
        }
        if(!empty($username)){
            $username=trim($username);
            $where.=" AND p1.hunter_name= '$username'";
        }
       // echo $where; exit;
        $order['id']="DESC";
        $_select = " p1.*,p2.username";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd_list` as p1
                left join  `jd_users` as p2  on   p1.business_id=p2.id                  
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);


       //echo $this->db->last_query();die;

      //  $a=  $this->Jd_task_jd_list_model->pageData($where,"*",$page,$epage,$order);
        $a['epage']=$epage;
        $a['page']=$page;

        foreach ($a['list'] as $id=>$v){
            $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['finishtime']);
            if(!empty($v['update'])){
                $a['list'][$id]['update']=date('Y-m-d H:i:s',$v['update']);
            }else{
                $a['list'][$id]['update']="";
            }
        }
        $this->sendjsonmsg($a);


    }


    /**
     * 导出订单信息
     * @param $page
     * @param $eapge
     * @param $orderid
     * @param $date1
     * @param $date2
     * @param $shop_name
     */
    public function excelorderviewlist($type=1,$date1="",$date2="",$username="",$orderid="",$shop_name=""){

        $page=1;
        $epage=20000;


        if(!$date1 ||$date1=='undefined' ){
            $date1=date('Y-m-d');
        }
        if(!$date2 ||$date2=='undefined' ){
            $date2=date('Y-m-d');
        }

        $where="  where  p1.status=2  AND  p1.type=$type";
        if($date1){
            $date1=strtotime(date('Y-m-d 00:00:00',strtotime($date1)));
            $where.=" AND p1.finishtime>$date1 ";
        }
        if($date2){
            $date2=strtotime(date('Y-m-d 23:59:59',strtotime($date2)));
            $where.=" AND p1.finishtime<$date2 ";
        }

        if(!empty($orderid) && $orderid!='undefined'){
            $where.=" AND p1.orderid= '$orderid'";
        }

        if(!empty($shop_name) && $shop_name!='undefined'){
            $shop_name=urldecode($shop_name);
            $where.=" AND p1.shop_name= '$shop_name'";
        }
        if(!empty($username) && $username!='undefined'){
            $username=urldecode($username);
            $where.=" AND p1.hunter_name= '$username'";
        }


    /*    '<td>' + value.id + '</td>\n' +
        '<td>' + value.addtime + '</td>\n' +
        '<td>' + value.update + '</td>\n' +
        '<td>' + value.orderid + '</td>\n' +
        '<td>   </td>\n' +
        '<td>' + value.shop_name + '</td>\n' +
        '<td>' + value.hunter_name + '</td>\n' +
        '<td>' + value.team + '</td>\n' +
        '<td>' + value.price + '</td>\n' +
        '<td>' + value.real_price + '</td>\n' +*/


        $order['id']="DESC";
        $_select = " p1.id,p1.addtime,p1.update,p1.orderid,p1.shop_name,p1.hunter_name,p1.awz,p1.team,p1.team,p1.price,p1.real_price";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd_list` as p1
                left join  `jd_users` as p2  on   p1.business_id=p2.id                  
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);

        //echo $this->db->last_query();die;
        //  $a=  $this->Jd_task_jd_list_model->pageData($where,"*",$page,$epage,$order);
        $a['epage']=$epage;
        $a['page']=$page;
        foreach ($a['list'] as $id=>$v){
            $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);

            if(!empty($v['update'])){
                $a['list'][$id]['update']=date('Y-m-d H:i:s',$v['update']);
            }else{
                $a['list'][$id]['update']="";
            }
        }
        $str[]='ID';
        $str[]='加入时间';
        $str[]='更新时间';
        $str[]='订单号';
        $str[]='店铺名';
        $str[]='测试员';
        $str[]='AWZ';
        $str[]='团队';
        $str[]='录入价格';
        $str[]='实际付款';
        $this->excel_out($str, $a['list'],"测试员订单记录");

    }


    public function getpddorderlist(){

        $this->getorderviewlist(2);
    }



    /**
     * 商户消费记录
     */
	public function businesspaylog(){
        $this->address='客户消费详情';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/businesspaylog');
    }
    /**
     * 获取商户消费记录
     */
    public function getbusinesspaylog(){

        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if(empty($epage)){
            $epage=10;
        }
        $this->load->model('Jd_pay_log_model');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $date1 = $this->input->post('date1')? $this->input->post('date1'):"";
        $date2 = $this->input->post('date2')? $this->input->post('date2'):"";
        $where="  where  p1.user_type=2  ";
        if($date1){
            $date1=strtotime($date1);
            $where.=" AND p1.addtime>$date1 ";
        }
        if($date2){
            $date2=strtotime($date2);
            $where.=" AND p1.addtime<$date2 ";
        }
        if(!empty($username)){
            $where.=" AND  p2.username= '$username'";
        }


        $order['id']="DESC";
        $_select = " p1.*,p2.username";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id                  
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id=>$v){
            $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
            switch ($v['type']){
                case 1 : $a['list'][$id]['type']='充值';break;
                case 2 : $a['list'][$id]['type']='发布任务';break;
                case 3 : $a['list'][$id]['type']='推荐奖励';break;
                case 4 : $a['list'][$id]['type']='测试员刷单';break;
                case 5 : $a['list'][$id]['type']='兑换金币';break;
                case 6 : $a['list'][$id]['type']='后台调整';break;
            }
        }


        $this->sendjsonmsg($a);

    }


    /**
     * 测试员资金记录
     */
    public function hunterpaylog(){
        $this->address='测试员消费详情';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/hunterpaylog');
    }


     public function hunterpaylogexcel($date1="",$date2="",$username=""){
         $page=1;
         $epage=2000;
         $this->load->model('Jd_pay_log_model');
         $_sql=" where  user_type=3 ";
         if($date1 && $date1!="undefined" ){
             $date1=strtotime($date1);
             $_sql.=" AND  p1.addtime>$date1 ";
         }
         if($date2  && $date2!="undefined"){
             $date2=strtotime($date2);
             $_sql.=" AND p1.addtime<$date2 ";
         }
         if(!empty($username) && $username!="undefined"){
             $username=urldecode($username);

             $_sql.=" AND  p2.username= '$username'";
         }
         $order['id']="DESC";
         $_select = " p1.id,p2.username,p1.type,p1.capital,p1.money,p1.balance,p1.capital_gold,p1.gold,p1.balance_gold,p1.addtime,p1.balance,p1.balance,p1.balance";
         $_order = " order by p1.id desc ";
         $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id                  
				 SQL ORDER LIMIT";
         $_data = array("sql" => $sql,
             "_sql" => $_sql,
             "_select" => $_select,
             "_order" => $_order,
             "limit" => "",
             "page" => $page,
             "epage" => $epage);

         $this->load->model('Jd_task_jd_model');
         $a = $this->Jd_task_jd_model->get_server_list($_data);
         foreach ($a['list'] as $id=>$v){
             $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
             switch ($v['type']){
                 case 1 : $a['list'][$id]['type']='充值';break;
                 case 2 : $a['list'][$id]['type']='发布任务';break;
                 case 3 : $a['list'][$id]['type']='推荐奖励';break;
                 case 4 : $a['list'][$id]['type']='测试员刷单';break;
                 case 5 : $a['list'][$id]['type']='兑换金币';break;
                 case 6 : $a['list'][$id]['type']='后台调整';break;
             }
         }
         $str[]='ID';
         $str[]='用户名';
         $str[]='类型';
         $str[]='本金';
         $str[]='变动资金';
         $str[]='余额';
         $str[]='原有金币';
         $str[]='金币变动';
         $str[]='剩余金币';
         $str[]='时间';
         $this->excel_out($str, $a['list'],"测试员资金记录");
     }


    /**
     * 商户资金记录导出
     * @param string $date1
     * @param string $date2
     * @param string $username
     * @throws PHPExcel_Exception
     * @throws PHPExcel_Writer_Exception
     */
     public function businesspaylogexcel($date1="",$date2="",$username=""){
         $page=1;
         $epage=2000;
         $this->load->model('Jd_pay_log_model');
         $_sql=" where  user_type=2 ";
         if($date1&& $date1!="undefined"){
             $date1=strtotime($date1);
             $_sql.=" AND  p1.addtime>$date1 ";
         }
         if($date2&& $date2!="undefined"){
             $date2=strtotime($date2);
             $_sql.=" AND p1.addtime<$date2 ";
         }
         if(!empty($username)&& $username!="undefined"){
             $username=urldecode($username);
             $_sql.=" AND  p2.username= '$username'";
         }
         $order['id']="DESC";
         $_select = " p1.id,p2.username,p1.type,p1.capital,p1.money,p1.balance,p1.capital_gold,p1.gold,p1.balance_gold,p1.addtime,p1.balance,p1.balance,p1.balance";
         $_order = " order by p1.id desc ";
         $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id                  
				 SQL ORDER LIMIT";
         $_data = array("sql" => $sql,
             "_sql" => $_sql,
             "_select" => $_select,
             "_order" => $_order,
             "limit" => "",
             "page" => $page,
             "epage" => $epage);

         $this->load->model('Jd_task_jd_model');
         $a = $this->Jd_task_jd_model->get_server_list($_data);
         foreach ($a['list'] as $id=>$v){
             $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
             switch ($v['type']){
                 case 1 : $a['list'][$id]['type']='充值';break;
                 case 2 : $a['list'][$id]['type']='发布任务';break;
                 case 3 : $a['list'][$id]['type']='推荐奖励';break;
                 case 4 : $a['list'][$id]['type']='测试员刷单';break;
                 case 5 : $a['list'][$id]['type']='兑换金币';break;
                 case 6 : $a['list'][$id]['type']='后台调整';break;
             }
         }
         $str[]='ID';
         $str[]='用户名';
         $str[]='类型';
         $str[]='本金';
         $str[]='变动资金';
         $str[]='余额';
         $str[]='原有金币';
         $str[]='金币变动';
         $str[]='剩余金币';
         $str[]='时间';
         $this->excel_out($str, $a['list'],"商户资金记录");

     }

    public function gethunterpaylog(){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if(empty($epage)){
            $epage=10;
        }
        $this->load->model('Jd_pay_log_model');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $date1 = $this->input->post('date1')? $this->input->post('date1'):"";
        $date2 = $this->input->post('date2')? $this->input->post('date2'):"";
        $_sql=" where  user_type=3 ";
        if($date1){
            $date1=strtotime($date1);
            $_sql.=" AND  p1.addtime>$date1 ";
        }
        if($date2){
            $date2=strtotime($date2);
            $_sql.=" AND p1.addtime<$date2 ";
        }
        if(!empty($username)){
            $_sql.=" AND  p2.username= '$username'";
        }
        $order['id']="DESC";
        $_select = " p1.*,p2.username";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id                  
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id=>$v){
            $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
            switch ($v['type']){
                case 1 : $a['list'][$id]['type']='充值';break;
                case 2 : $a['list'][$id]['type']='发布任务';break;
                case 3 : $a['list'][$id]['type']='推荐奖励';break;
                case 4 : $a['list'][$id]['type']='测试员刷单';break;
                case 5 : $a['list'][$id]['type']='兑换金币';break;
                case 6 : $a['list'][$id]['type']='后台调整';break;
            }
        }


        $this->sendjsonmsg($a);

    }


    /**
     * 欠费用户列表页
     */
    public function owemoney(){
        $this->address='欠费用户列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/ownmoney');
    }


    /**
     * 获取拥有欠款的商户
     */
    public function geyowemoneylist(){
        $this->load->model('Jd_buniess_balance_model');
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if(empty($epage)){
            $epage=10;
        }
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $date = $this->input->post('date')? $this->input->post('date'):"";
        $date1 = $this->input->post('date1')? $this->input->post('date1'):"";
        $date2 = $this->input->post('date2')? $this->input->post('date2'):"";
        $date=date('Y-m-d');
        $where=" 1=1  ";
        if($date){
         // $where.=" AND date='$date' ";
        }
        if($date1){
            $date1=strtotime($date1);
            $where.=" AND addtime>$date1 ";
        }
        if($date2){
            $date2=strtotime($date2);
            $where.=" AND addtime<$date2 ";
        }
        if(!empty($username)){
            $where.=" AND username= $username";
        }
        $order['id']="DESC";
        $row= $this->Jd_buniess_balance_model->pageData($where,"*",$page,$epage,$order);
        $this->load->model('Jd_users_model');
     /*   foreach ($row['list'] as $id=>$v){
            if(empty($v['username'])){
               $userinfo= $this->Jd_users_model->GetUserById( $v['user_id']);
            }
        }*/
        $row['epage']=$epage;
        $row['page']=$page;
        $this->sendjsonmsg($row);
    }


    /**
     * excel导出欠款用户
     * @param $date1
     * @param $date2
     * @param $username
     */
    public function GetExcleOwemoneyList($date1,$date2,$username){
        $this->load->model('Jd_buniess_balance_model');
        $page = 1;
        $epage = 2000;

        $date=date('Y-m-d');
        $date="";

        $where=" 1=1  ";
        if($date){
            $where.=" AND date='$date' ";
        }
        if($date1&& $date1!='undefined'){
            $date1=strtotime($date1);
            $where.=" AND addtime>$date1 ";
        }
        if($date2&& $date2!='undefined'){
            $date2=strtotime($date2);
            $where.=" AND addtime<$date2 ";
        }
        if(!empty($username) && $username!='undefined'){
            $username=urldecode($username);
            $where.=" AND username= $username";
        }
        $order['id']="DESC";
        $select="id,username,saler,money,gold,balance,`date`";
        $row= $this->Jd_buniess_balance_model->pageData($where,$select,$page,$epage,$order);
        $str[]='ID';
        $str[]='用户名+';
        $str[]='销售';
        $str[]='总本金';
        $str[]='总金币';
        $str[]='余额';
        $str[]='日期';
       $this->excel_out($str,$row['list'],"欠款用户列表");
    }



    /**
     * 查看京东任务列表
     */
    public function pddorderview(){
        $this->address='拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddorderview');
    }

    /**
     * 查看拼多多任务列表
     */
    public function pddtasklist(){
        $this->address='拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddtasklist');
    }


    public function relodpddtask($id){

        $this->address='拼多多任务修改';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');

        $this->load->model('Jd_task_jd_model');
        $row=$this->Jd_task_jd_model->getonebyid($id);
        $str=explode( "/",$row['picurl']);
        if(  isset($str[1]) && $str[1]=='pic'){
            $row['picurl']=base_url()."public/uploads". $row['picurl'];
        }

        $this->load->view('Customer/relodpddtask',$row);
    }


    /**
     * 查看京东任务列表
     */
    public function pddtasksort(){
        $this->address='拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddtasksort');
    }





    /**
     * 查看京东任务列表
     */
    public function jdtasklist(){
        $this->address='京东任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jdtasklist');
    }





    /**
     * 测试员管理
     */
    public function Hunter(){
        $this->address='测试员管理';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/hunter');
    }


    /**
     * 获取测试员列表
     */
    public function gethunterlist(){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $date = $this->input->post('date')? $this->input->post('date'):"";
        if(!$date){
            $date=date('Y-m-d');
        }
        $month=date('Y-m-1',strtotime($date));
        $_sql = "where p1.`group`=3  ";
        if(!empty($username)){
            $_sql.=" AND p1.username= '$username'";
        }
        $_select = " p1.id,p1.username,p1.team,p2.usemoney,p2.sendmoney,p1.money,p3.finishnub,p1.password";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_hunter_total_day` as p2  on   p1.id=p2.user_id  AND p2.`date`='$date'
                 left join  `jd_hunter_total_month` as p3  on   p1.id=p3.user_id      AND p3.`date`='$month'             
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);


        foreach ($result['list'] as $id=>$v){


            $result['list'][$id]['usemoney']=intval($v['usemoney']);
            $result['list'][$id]['sendmoney ']=intval($v['sendmoney']);

            //$result['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
         //   $result['list'][$id]['money']=$v['pay_price']*$v['number']*$v['each_single'];
            // $a['list'][$id]['status']=$v['status']==0?'待审核':'通过审核';
        }
        $this->sendjsonmsg($result);
    }


    /**
     * 获取商户列表列表
     */
    public function GetBusinessList(){
        $page = $this->input->post('page');
            $epage = $this->input->post('epage');
            $username = $this->input->post('username')? $this->input->post('username'):"";
            $phone = $this->input->post('phone')? $this->input->post('phone'):"";

            $date = $this->input->post('date')? $this->input->post('date'):"";
            if(!$date){
            $date=date('Y-m-d');
        }
        $month=date('Y-m-1',strtotime($date));
        $_sql = "where p1.`group`=2 ";
        if(!empty($username)){
            $_sql.=" AND p1.username= '$username'";
        }
        if(!empty($phone)){
            $_sql.=" AND p1.phone= '$phone'";
        }



        $_select = " p1.*,p2.addtime as  'newtime'";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_task_jd` as p2  on   p1.lasttaskid=p2.id                
                             
			   SQL  group  by   p1.id  ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');


        $result = $this->Jd_users_model->get_server_list($_data);


        foreach ($result['list'] as $id=>$v){
            if(!empty($v['newtime'])){
                $result['list'][$id]['newtime']=date('Y-m-d H:i:s',$v['newtime']);
            }else{
                $result['list'][$id]['newtime']="";
            }



            //   $result['list'][$id]['money']=$v['pay_price']*$v['number']*$v['each_single'];
            $result['list'][$id]['status']=$v['status']==0?'禁用中':'正常';
        }
        $this->sendjsonmsg($result);
    }


    /**
     * 获取商户列表列表
     */
    public function GetALLuserList(){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $phone = $this->input->post('phone')? $this->input->post('phone'):"";

        $date = $this->input->post('date')? $this->input->post('date'):"";
        if(!$date){
            $date=date('Y-m-d');
        }
        $month=date('Y-m-1',strtotime($date));
        $_sql = "where 1=1 ";
        if(!empty($username)){
            $_sql.=" AND p1.username= '$username'";
        }
        if(!empty($phone)){
            $_sql.=" AND p1.phone= '$phone'";
        }
        $_select = " p1.*,p2.addtime as  'newtime'";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_task_jd` as p2  on   p1.lasttaskid=p2.id               
                             
			   SQL    ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $result = $this->Jd_users_model->get_server_list($_data);
        $teamlist=$this->getteamlist(1);
        $channellist=$this->getchannellist(1);

        foreach ($result['list'] as $id=>$v){
            if(!empty($v['newtime'])){
                $result['list'][$id]['newtime']=date('Y-m-d H:i:s',$v['newtime']);
            }else{
                $result['list'][$id]['newtime']="";
            }
            switch ($v['group']){
                case 1 : $result['list'][$id]['type']='管理员';break;
                case 2 : $result['list'][$id]['type']='商家';break;
                case 3 : $result['list'][$id]['type']='测试员';break;
                case 4 : $result['list'][$id]['type']='财务';break;
                case 5 : $result['list'][$id]['type']='客服';break;
                case 6 : $result['list'][$id]['type']='销售';break;
            }
            $result['list'][$id]['teamname']=$v['team']?$teamlist[$v['team']]:"";
            $result['list'][$id]['channelname']=$v['channel']?$channellist[$v['channel']]:"";
            //   $result['list'][$id]['money']=$v['pay_price']*$v['number']*$v['each_single'];
            $result['list'][$id]['status']=$v['status']==0?'禁用中':'正常';
        }
        $this->sendjsonmsg($result);
    }



    /**
     * 获取京东(拼多多)任务列表
     */
    public function getjdtasklist($type=1){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $status = $this->input->post('status');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $shop_name = $this->input->post('shop_name')? $this->input->post('shop_name'):"";
        $keyword = $this->input->post('keyword')? $this->input->post('keyword'):"";
        $date1 = $this->input->post('date1')? $this->input->post('date1'):date('Y-m-d');
        $date2 = $this->input->post('date2')? $this->input->post('date2'):date('Y-m-d');
        if($status){
            $date1="";
            $date2 ='';
        }

         $_sql="where  p1.type=$type";
         if($status==2){
            $_sql.=" AND p1.status=2 ";
         }else{
             if($status==1){
                 $_sql.=" AND p1.status=1 ";
             }
         }
         if($date1){
            $date1=strtotime(date('Y-m-d 00:00:00',strtotime($date1)));
             $_sql.=" AND p1.addtime>$date1 ";
        }
        if($date2){
            $date2=strtotime(date('Y-m-d 23:59:59',strtotime($date2)));
            $_sql.=" AND p1.addtime<$date2 ";
        }
        if(!empty($username)){
            $_sql.=" AND p2.username= '$username'";
        }
        if(!empty($shop_name)){
            $_sql.=" AND p1.shop_name= '$shop_name'";
        }
        if(!empty($key_word)){
            $_sql.=" AND p1.keyword= '$keyword'";
        }


        $_select = " p1.*,p2.username,p2.salername";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd` as p1             
            left join jd_users as p2 on p2.id=p1.business_id 
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);


        foreach ($result['list'] as $id=>$v){
            $result['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
            $result['list'][$id]['money']=round($v['pay_price']*$v['number']*$v['each_single'],2);
            $result['list'][$id]['number']=$v['finish_nub']."/".$v['number'];
            $result['list'][$id]['Surplus']=$v['number']-$v['finish_nub'];
            switch ($v['pay_type']){
                case 1:$result['list'][$id]['pay_type']='全部开团';break;
                case 2:$result['list'][$id]['pay_type']='单独购买';break;
                case 3:$result['list'][$id]['pay_type']='优先参团';break;
            }



           // $a['list'][$id]['status']=$v['status']==0?'待审核':'通过审核';
        }
        $this->sendjsonmsg($result);

    }


    public function getjdtasklistexcel($type=1,$date1="",$date2="",$username="",$shop_name="",$keyword=""){

        $page = 1;
        $epage = 20000;
        $_sql="where  p1.type=$type";


        $date1 = $date1? $date1:date('Y-m-d');
        $date2 = $date2? $date2:date('Y-m-d');


        if($date1){
            $date1=strtotime(date('Y-m-d 00:00:00',strtotime($date1)));
            $_sql.=" AND p1.addtime>$date1 ";
        }
        if($date2){
            $date2=strtotime(date('Y-m-d 23:59:59',strtotime($date2)));
            $_sql.=" AND p1.addtime<$date2 ";
        }
        if(!empty($username)){
            $_sql.=" AND p2.username= '$username'";
        }
        if(!empty($shop_name)){
            $_sql.=" AND p1.shop_name= '$shop_name'";
        }
        if(!empty($key_word)){
            $_sql.=" AND p1.keyword= '$keyword'";
        }



        $_select = " p1.id,p1.addtime,p1.goods_name,p1.finish_nub,p1.number,p1.keyword,p1.shop_name,p1.each_single,pay_price,pay_type";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd` as p1             
            left join jd_users as p2 on p2.id=p1.business_id 
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($result['list'] as $id=>$v){
            $result['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
            switch ($v['pay_type']){
                case 1:$result['list'][$id]['pay_type']='全部开团';break;
                case 2:$result['list'][$id]['pay_type']='单独购买';break;
                case 3:$result['list'][$id]['pay_type']='优先参团';break;
            }
        }
        $str[]='ID';
        $str[]='加入时间';
        $str[]='主商品';
        $str[]='完成单';
        $str[]='总单量';
        $str[]='关键字';
        $str[]='商铺名';
        $str[]='每单数量';
        $str[]='录入价格';
        $str[]='拼团';
        $this->excel_out($str, $result['list'],"今日任务列表");
    }



    /**
     * 京东任务排序
     */
    public function jdtasksort(){

        $this->address='京东任务排序';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jdtasksort');

    }


    /**
     * 设置任务子单推送间隔
     */
    public function SetTaskInterval(){
        $id = $this->input->post('id');
        $value = $this->input->post('value');
        $type = $this->input->post('type')?$this->input->post('type'):1;
        $value=intval($value);
        $this->load->model('Jd_task_jd_model');
        $result=$this->Jd_task_jd_model->UpdatelastSendInterval($id,$value);
        if($type==1 && $result){
            $result=$this->Jd_task_jd_model->UpdateStatus($id,2);
        }
        if($type==2 && $result){
            $result=$this->Jd_task_jd_model->UpdateStatus($id,1);
        }
        if($result){
            $msgp['msg']="设置成功";
            $this->sendjsonmsg($msgp);
        }
        $msgp['code']=1;
        $msgp['msg']="设置失败";
        $this->sendjsonmsg($msgp);
    }





    public function TaskCancel(){
        $id = $this->input->post('id');
        $this->load->model('Jd_task_jd_model');
        $result=$this->Jd_task_jd_model->UpdateStatus($id,4);
        if($result){
            $this->load->model('Jd_task_jd_list_model');
            $result=$this->Jd_task_jd_list_model->CancelStatus($id);
            if($result){
                $this->load->model('Jd_task_jd_list_pool_model');
                $this->Jd_task_jd_list_pool_model->CancelStatus($id);
            }
            if($result) {
                $msgp['msg'] = "设置成功";
                $this->sendjsonmsg($msgp);
            }
        }
        $msgp['code']=1;
        $msgp['msg']="设置失败";
        $this->sendjsonmsg($msgp);
    }


    public function ResetStatus(){
        $id = $this->input->post('id');
        $this->load->model('Jd_task_jd_list_pool_model');
        $result=$this->Jd_task_jd_list_pool_model->ResetStatus($id);
        if($result) {
            $msgp['msg'] = "重置成功";
            $this->sendjsonmsg($msgp);
        }
        $msgp['code']=1;
        $msgp['msg']="重置失败";
        $this->sendjsonmsg($msgp);
    }



	/**
     * $type :推送类型 1京东  2 拼多多
     * 推送任务至任务池中
     */
	public function  sendtask($type=1){
	    $this->load->model('Jd_task_jd_model');
        $row=$this->Jd_task_jd_model->getwaittask();
        if(empty($row)){
            $msg['code']=1;
            $msg['msg']="没有待推送的任务";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_task_jd_list_model');
        $this->load->model('Jd_task_jd_list_pool_model');
        $idlist=array();
        $taskidstr=array();
        $this->db->trans_begin();
        foreach ($row as  $key=>$value){
            $taskid=$value['id'];
            $interval=$value['interval'];
            $lastsendtime=$value['lastsendtime']?$value['lastsendtime']:0;
            $realinterval=intval(time()-$lastsendtime)/60;
            if($realinterval<$interval){
                continue;
            }
            $listrow= $this->Jd_task_jd_list_model->getminlitstake($taskid);
            $listrow['listid']=$listrow['id'];
            unset($listrow['id']);
            $listrow['addtime']=time();
            unset($listrow['hunter_id']);
            unset($listrow['hunter_name']);
            unset($listrow['team']);
            $listrow['shop_name']=$value['shop_name'];
            $r=$this->Jd_task_jd_list_pool_model->addtasklisttopoll($listrow);
            if($r){
                $idlist[]=$listrow['listid'];
                $taskidstr[]=$taskid;
            }
        }
        if(!empty($idlist)){
            $result= $this->Jd_task_jd_list_model->updatapool($idlist);
            if($result){
                $result=$this->Jd_task_jd_model->UpdatelastSendTime($taskidstr);
                if($result){
                   $this->db->trans_commit();
                    $msg['code']=0;
                    $msg['msg']="推送成功";
                    $this->sendjsonmsg($msg);
               }
            }
        }else{
            $msg['code']=1;
            $msg['msg']="没有合适任务或推送失败";
            $this->sendjsonmsg($msg);
        }
	}


    /**
     * 充值审核列表
     */
	public function paylimit(){
        $this->address='充值审核列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/paylimit');
      }


      public function payfinish(){
          $this->address='充值完成列表';
          $this->load->view('Customer/head');
          $this->load->view('Customer/left');
          $this->load->view('Customer/payfinish');
	}

     /**
      * 获取充值列表
      */
      public function getpaylistaction(){
          $page = $this->input->post('page');
          $epage = $this->input->post('epage');

          $type = $this->input->post('type');

          if(empty($epage)){
              $epage=10;
          }

          $username = $this->input->post('username')? $this->input->post('username'):"";
          $date1 = $this->input->post('date1')? $this->input->post('date1'):"";
          $date2 = $this->input->post('date2')? $this->input->post('date2'):"";
          $where=" status=0  ";
          if($type){
              $where=" status>0 ";
          }

          if($date1){
              $date1=strtotime($date1);
              $where.=" AND addtime>$date1 ";
          }
          if($date2){
              $date2=strtotime($date2);
              $where.=" AND addtime<$date2 ";
          }
          if(!empty($username)){
              $where.=" AND account= '$username'";
          }
          $this->load->model('Jd_pay_model');
          $order['status']='ASC';
          $order['id']='desc';
          $a=  $this->Jd_pay_model->pageData($where,"*",$page,$epage,$order);
          $a['epage']=$epage;
          $a['page']=$page;
          foreach ($a['list'] as $id=>$v){
              $a['list'][$id]['addtime']=date('Y-m-d H:i:s',$v['addtime']);
              $a['list'][$id]['picurl']=base_url()."public/uploads".$v['picurl'];

              switch ($v['status']){
                  case 0:$a['list'][$id]['status']='待审核';break;
                  case 1:$a['list'][$id]['status']='已通过';break;
                  case 2:$a['list'][$id]['status']='已拒绝';break;
              }
          }

          $this->sendjsonmsg($a);
      }


    /**
     * 审核商户的充值
     * @param $id
     */
    public function  PayExamine(){
        $id = $this->input->post('id');
        if($this->group!=4 && $this->group!=1){
            $msg['code']=1;
            $msg['msg']="您不是财务无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');

        $a=  $this->Jd_pay_model->approvepay($id);
        $a=  $this->Jd_pay_model->getonebyid($id);

        if(!$a){
            $msg['code']=2;
            $msg['msg']="审核失败或者重复审核";
            $this->sendjsonmsg($msg);
        }
        $row['money']=$a['money'];
        $row['user_id']=$a['user_id'];
        $this->project=3;
        $result=$this->moneyupdate($row,1,$id);
        if($result){
            $this->sendjsonmsg();
        }
        if(!$a){
            $msg['code']=0;
            $msg['msg']="审核成功";
            $this->sendjsonmsg($msg);
        }

    }

    /**
     * 拒绝充值
     */
    public function PayRefuse(){
        $id = $this->input->post('id');
        $remarks = $this->input->post('remarks');
        $this->project=3;
        if($this->group!=4 && $this->group!=1){
            $msg['code']=1;
            $msg['msg']="您不是财务无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');
        $a=  $this->Jd_pay_model->PayRefuse($id,$remarks);
        if(!$a){
            $msg['code']=2;
            $msg['msg']="状态更新失败";
            $this->sendjsonmsg($msg);
        }
        $msg['code']=0;
        $msg['msg']="拒绝完成";
        $this->sendjsonmsg($msg);
    }


    /**
     *
     * 计算商户所有余额状态
     */
    public function totalbusiness(){
        $now=time();
        $yestodaydate=date("Y-m-d",strtotime("-1 day"));
        $yestoday=strtotime($yestodaydate); //昨天凌晨
        $this->load->model('Jd_task_jd_list_model');
        $row= $this->Jd_task_jd_list_model->totalbunissmoney($yestoday);
        $this->load->model('Jd_buniess_balance_model');
        $this->Jd_buniess_balance_model->addlog($row,$yestodaydate);
    }


    //销售情况页面
    public function Salelist() {
        $this->load->library('parser');
        $data['title'] = '销售列表';
        $this->address='销售列表';


        $this->load->view('Customer/head',$data);
        $this->load->view('Customer/left');
        $this->load->view('Customer/Salelist');
    }


    /**
     * 获取销售列表
     */
    public function GetAllSaleList(){

        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $phone = $this->input->post('phone')? $this->input->post('phone'):"";

        $date = $this->input->post('date')? $this->input->post('date'):"";
        if(!$date){
            $date=date('Y-m-d');
        }
        $month=date('Y-m-1',strtotime($date));
        $_sql = "where p1.`group`=6 ";
        if(!empty($username)){
            $_sql.=" AND p1.username= '$username'";
        }
        if(!empty($phone)){
            $_sql.=" AND p1.phone= '$phone'";
        }
        $_select = " p1.*,p2.extension_nub,p2.extension_nub_day,p2.extension";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_user_total` as p2  on   p1.id=p2.user_id              
                             			   SQL  group  by   p1.id  ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $result = $this->Jd_users_model->get_server_list($_data);
        foreach ($result['list'] as $id=>$v){
            $result['list'][$id]['status']=$v['status']==0?'禁用中':'正常';
             $result['list'][$id]['link']=$this->SetExtensionLink($v['id']);
        }

        //var_dump($result); exit;
        $this->sendjsonmsg($result);

    }



    public function SaleStatus(){

        $this->load->library('parser');


        $this->address='销售情况';

        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/SaleStatus');
    }


    /**
     * 获取销售状况
     */
    public  function  GetSaleStatuslist(){
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username')? $this->input->post('username'):"";
        $phone = $this->input->post('phone')? $this->input->post('phone'):"";

        $date = $this->input->post('date')? $this->input->post('date'):"";
        if(!$date){
            $date=date('Y-m-d');
        }
        $month=date('Y-m-1',strtotime($date));
        $_sql = "where p1.`group`=6 ";
        if(!empty($username)){
            $_sql.=" AND p1.username= '$username'";
        }
        if(!empty($phone)){
            $_sql.=" AND p1.phone= '$phone'";
        }
        $_select = " p1.*, p2.task_nub,p2.extension_nub,p2.extension_nub_day,p2.extension";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_user_total` as p2  on   p1.id=p2.user_id              
                             			   SQL  group  by   p1.id  ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $result = $this->Jd_users_model->get_server_list($_data);

        $channellist=$this->getchannellist(1);
        foreach ($result['list'] as $id=>$v){
            $result['list'][$id]['channelname']=$v['channel']?$channellist[$v['channel']]:"";
        }

        //var_dump($result); exit;
        $this->sendjsonmsg($result);


    }







    public function userControl() {
        $this->load->library('parser');

        $this->address='用户管理';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $data['salerlist']=$this->getsalerlist("id,username");
        $this->load->view('Customer/businesslist',$data);
    }


    /**
     * 手动调整用户资金
     */
    public function  Manualpay(){
          $user_id=$this->input->post('user_id');
          $money=$this->input->post('money')?$this->input->post('money'):0;
          $gold=$this->input->post('gold')?$this->input->post('gold'):0;
          $remrk=$this->input->post('remrk')?$this->input->post('remrk'):"";


        if($this->group!=4 && $this->group!=1){
            $msg['code']=1;
            $msg['msg']="您不是财务无权资金改动";
            $this->sendjsonmsg($msg);
        }
          $row['user_id']=$user_id;
          $row['money']=$money;
          $row['gold']=$gold;
          $row['remarks']=$remrk;
          $r= $this->moneyupdate($row,6,$this->user_id);
          if(!$r){
              $msg['code']=1;
              $msg['msg']="资金改动失败";
              $this->sendjsonmsg($msg);
          }


         $this->sendjsonmsg();
    }


    /**
     *  手动调整测试员资金
     */
    public function ManuaHunterMoney(){
        $user_id=$this->input->post('user_id');
        $money=$this->input->post('money');
        if($this->group!=4 && $this->group!=1){
            $msg['code']=1;
            $msg['msg']="您不是财务无权资金改动";
            $this->sendjsonmsg($msg);
        }
        $row['user_id']=$user_id;
        $row['money']=$money;


        $this->db->trans_begin();
        $r= $this->moneyupdate($row,6,$this->user_id);
        if(!$r){
            $this->db->trans_rollback();
            $msg['code']=1;
            $msg['msg']="资金改动失败";
            $this->sendjsonmsg($msg);
        }
        if($money>0){
            $hunterinfo=$this->getcuserinfo(1,$user_id);
            if($hunterinfo['group']==3){
                $this->load->model('Jd_hunter_total_day_model');
                $r=  $this->Jd_hunter_total_day_model->addsendmoney($row);
            }
        }
        if(!$r){
            $this->db->trans_rollback();
            $msg['code']=1;
            $msg['msg']="资金改动失败";
            $this->sendjsonmsg($msg);
        }
        $this->db->trans_commit();
        $this->sendjsonmsg();
     }


    /**
     * 为商户分配销售
     */
     public function distribution(){
         $user_id=$this->input->post('user_id');
         $salerid=$this->input->post('salerid');
         $this->load->model('Jd_users_model');
         $salername=$this->Jd_users_model->GetUserById($salerid,"username");
         $salername=$salername['username'];
         $row['user_id']=$user_id;
         $row['salername']=$salername;
         $row['recommender']=$salername;
         $row['recommender_id']=$salerid;
         $result=$salername=$this->Jd_users_model->updata_user($row);
         if($result){
             $this->sendjsonmsg();
         }
         $msg['code']=1;
         $msg['msg']='分配失败';
         $this->sendjsonmsg($msg);
     }


    /**
     * 获取用户佣金配置信息
     */
      public  function  getcommissionbyuser(){
         $user_id=$this->input->post('user_id');
         $this->load->model('Jd_users_model');
         $commissions=$this->Jd_users_model->GetUserById($user_id,"commission,commission2");
          $commission=$commissions['commission'];
          $commission2=$commissions['commission2'];
         if(empty($commission)){
             $commission=array(200,100,100,10);
         }else{
             $commission=unserialize($commission);
         }
          if(empty($commission2)){
              $commission2=array(50,50,100,10);
          }else{
              $commission2=unserialize($commission2);
          }
          $commission3=array_merge($commission,$commission2);

         $msg['code']=0;
         $msg['data']=$commission3;
         $this->sendjsonmsg($msg);
     }


    /**
     * 设置用户佣金信息
     */
     public function setcommission(){
         $user_id=$this->input->post('user_id');
         $xiaoyu1000=$this->input->post('xiaoyu1000')?$this->input->post('xiaoyu1000'):200;
         $xiaoyu5000=$this->input->post('xiaoyu5000')?$this->input->post('xiaoyu5000'):100;
         $xiaoyu10000=$this->input->post('xiaoyu10000')?$this->input->post('xiaoyu10000'):100;
         $dayu10000=$this->input->post('dayu10000')?$this->input->post('dayu10000'):10;


         $value1=$this->input->post('value1')?$this->input->post('value1'):50;
         $value2=$this->input->post('value2')?$this->input->post('value2'):50;
         $value3=$this->input->post('value3')?$this->input->post('value3'):100;
         $value4=$this->input->post('value4')?$this->input->post('value4'):10;

         $commission[]=$xiaoyu1000;
         $commission[]=$xiaoyu5000;
         $commission[]=$xiaoyu10000;
         $commission[]=$dayu10000;

         $commission2[]=$value1;
         $commission2[]=$value2;
         $commission2[]=$value3;
         $commission2[]=$value4;

         $commission=serialize($commission);
         $commission2=serialize($commission2);
         $row['user_id']=$user_id;
         $row['commission']=$commission;
         $row['commission2']=$commission2;
         $this->load->model('Jd_users_model');
         $result=$salername=$this->Jd_users_model->updata_user($row);
         if($result){
             $this->sendjsonmsg();
         }
         $msg['code']=1;
         $msg['msg']='设置佣金失败';
         $this->sendjsonmsg($msg);
     }

    /**
     * 禁止或者启用用户
     */
     public function stopuser(){
         $user_id=$this->input->post('user_id');
         $this->load->model('Jd_users_model');
         $status=$this->Jd_users_model->GetUserById($user_id,"status");
         $row['user_id']=$user_id;
         $row['status']=abs(1-$status['status']);
         $result=$salername=$this->Jd_users_model->updata_user($row);
         if($result){
             $this->sendjsonmsg();
         }
         $msg['code']=1;
         $msg['msg']='修改状态成功';
         $this->sendjsonmsg($msg);
     }








     public function relodjdtask($id){
         $this->address='修改任务';
         $this->load->view('Customer/head');
         $this->load->view('Customer/left');
         $this->load->model('Jd_task_jd_model');
         $row=$this->Jd_task_jd_model->getonebyid($id);
         $str=explode( "/",$row['picurl']);
         if(  isset($str[1]) && $str[1]=='pic'){
             $row['picurl']=base_url()."public/uploads". $row['picurl'];
         }
         $this->load->view('Customer/relodjdtask',$row);
     }


    /**
     * 编辑任务
     */
     public function EditTask(){
         if(empty($row)){
             $row= $this->input->post();
         }
         $this->load->model('Jd_task_jd_model');


         if(!empty($row['pic'])){
             $pic=$this->movepic($row['pic']);
             if(!$pic){
                 $msg['code'] =  1;
                 $msg['msg'] =  '图片上传失败';
                 $this->sendjsonmsg($msg);
             }
             $newrow=array();
             $newrow['user_id']=$this->user_id;
             $newrow['address']=$pic['path'];
             $newrow['url']=$pic['url'];
             $newrow['addtime']=time();
             $this->load->model('Jd_pic_model');
             $result= $this->Jd_pic_model->addpic($newrow);

             if(!$result){
                 $msg['code'] =  1;
                 $msg['msg'] =  '图片上传失败';
                 $this->sendjsonmsg($msg);
             }
             $row['pic']=$result;
             $row['picurl']=$pic['url'];
         }

         foreach ($row as $id=>$v){
             if(empty($v) && $id!="coupon" && $id!="remarks"&& $id!="pic"){
               $msg['code'] = 1;
                 $msg['msg'] = '缺少参数';
                 $this->sendjsonmsg($msg);
             }
         }
         $this->load->model('Jd_task_jd_model');
         //$result=  $this->Jd_task_jd_model->getonebyid( $row['id']);
         if(isset($row['number'])){
             unset($row['number']);
         }
         if(isset($row['pay_price'])){
             unset($row['pay_price']);
         }
         if(isset($row['each_single'])){
             unset($row['each_single']);
         }
         $result= $this->Jd_task_jd_model->taskupdate($row);

         unset($row['pic']);
         if($result){
             $this->load->model('Jd_task_jd_list_model');
             $result= $this->Jd_task_jd_list_model->taskupdate($row);

             if($result){
                 $this->load->model('Jd_task_jd_list_pool_model');
                 $this->Jd_task_jd_list_pool_model->taskupdate($row);
             }
             if($result) {
                 $this->sendjsonmsg();
             }
         }
         $msg['code']=1;
         $msg['msg']='修改失败';
         $this->sendjsonmsg($msg);

     }



    /**
     * 手动增加用户
     */
    public function adduser(){
        if( $this->group!=1){
            $msg['code']=1;
            $msg['msg']="只有管理员可以增加用户";
            $this->sendjsonmsg($msg);
        }

        $username=$this->input->post('username');
        $password=$this->input->post('password');
        $phone=$this->input->post('phone');
        $group=$this->input->post('group');


        $row['username']=$username;
        $row['password']=$password;
        $row['phone']=$phone;
        $row['group']=$group;
        $row['regtime']=time();


        foreach ($row as $id=>$v){
            if(empty($v)){
                $msg['code']=1;
                $msg['msg']="缺少参数";
                $this->sendjsonmsg($msg);

            }

        }

        $this->load->model('Jd_users_model');
        $status=$this->Jd_users_model->adduser($row);
        if($status){
            $this->sendjsonmsg();
        }
        $msg['code']=1;
        $msg['msg']="添加失败";
        $this->sendjsonmsg($msg);
    }


    /**
     * 编辑用户信息
     */
    public function edituser(){
        if( $this->group!=1){
            $msg['code']=1;
            $msg['msg']="只有管理员可以修改用户";
            $this->sendjsonmsg($msg);
        }
        $user_id=$this->input->post('user_id');
        $username=$this->input->post('username');
        $password=$this->input->post('password');
        $phone=$this->input->post('phone');
        $group=$this->input->post('group');
        $channel=$this->input->post('channel');
        $team=$this->input->post('team');
        $row['user_id']=$user_id;
        $row['username']=$username;
        $row['password']=$password;
        $row['phone']=$phone;
        $row['group']=$group;
        $row['channel']=$channel;
        $row['team']=$team;
        $this->load->model('Jd_users_model');
        $status=$this->Jd_users_model->updata_user($row);
        if($status){
            $this->sendjsonmsg();
        }
        $msg['code']=1;
        $msg['msg']="修改失败";
        $this->sendjsonmsg($msg);

    }


     //测试员管理页面
    public function CheckTheButton() {
        $this->load->library('parser');

        $this->address='测试员管理';


        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jd_CheckTheButton');
    }


    //账户管理页面
    public function accountManagement() {
        $this->load->library('parser');
        $data['title'] = '用户管理';
        $this->address='用户管理';

        $this->load->view('Customer/head',$data);
        $this->load->view('Customer/left');
        $data['grouplist']=$this->getgrouplist();
        unset($data['grouplist'][0]);
        $data['teamlist']=$this->getteamlist();
        $data['channellist']=$this->getchannellist();
        $this->load->view('Customer/userControl',$data);
    }

    /**
     * 获取销售列表
     */
    public function getsalerlist($select="*"){
        $this->load->model('Jd_users_model');
        return  $row= $this->Jd_users_model->getuserbygroup(6,$select);
    }














}
